<html>
<head><meta charset="utf-8"><title>builtin macros · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html">builtin macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233420239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233420239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233420239">(Apr 07 2021 at 02:16)</a>:</h4>
<p>so am I correct in thinking that the matcher signature of builtin macros is just completely fake and ignored by the compiler? looking at the <code>asm</code> macro, whose definition looks extremely bogus:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="p">(</span><span class="s">"assembly template"</span><span class="p">,</span><span class="w"></span>
<span class="w">            </span><span class="cp">$(</span><span class="n">operands</span><span class="p">,)</span><span class="o">*</span><span class="w"></span>
<span class="w">            </span><span class="cp">$(</span><span class="n">options</span><span class="p">(</span><span class="cp">$(</span><span class="n">option</span><span class="p">),</span><span class="o">*</span><span class="p">))</span><span class="o">?</span><span class="w"></span>
<span class="w">        </span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>
<p>so is the idea that the definition contained there is only used for generating documentation?</p>



<a name="233420305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233420305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233420305">(Apr 07 2021 at 02:17)</a>:</h4>
<p>follow-up question: is there any reason why "builtin macros" can't be replaced by function-like procedural macros? looking at where builtin macros are defined, it looks like they're already using TokenStream, so can these be migrated away from being bespoke fake-declarative-macro machinery into real procedural macros?</p>



<a name="233421416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233421416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233421416">(Apr 07 2021 at 02:31)</a>:</h4>
<p>real procedural macros don't have access to type information</p>



<a name="233421870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233421870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233421870">(Apr 07 2021 at 02:37)</a>:</h4>
<p>hm, is that the only difference? looking at the list of builtin macros, it feels like that format_args is the only one that I'd feel like might be making use of that, and even then I don't see why format_args wouldn't just naively expand to something that assumes the format string is correct, and leave the job of typechecking to later in the pipeline</p>



<a name="233422145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233422145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233422145">(Apr 07 2021 at 02:40)</a>:</h4>
<p>Builtin macros don't have type info either</p>



<a name="233422181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233422181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233422181">(Apr 07 2021 at 02:41)</a>:</h4>
<p>And yeah, these definitions are just for documentation</p>



<a name="233422290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233422290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233422290">(Apr 07 2021 at 02:42)</a>:</h4>
<p>does the built-in macro machinery work with the <code>macro</code> keyword?</p>



<a name="233424013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424013">(Apr 07 2021 at 03:05)</a>:</h4>
<p>The <code>macro</code> keyword is used by 'macros 2.0', which is still under development</p>



<a name="233424014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424014">(Apr 07 2021 at 03:05)</a>:</h4>
<p>It's also used to declare bultin macros, but there's no fundamental reason that those macros are declared with <code>macro</code> instead of <code>macro_rules</code></p>



<a name="233424083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424083">(Apr 07 2021 at 03:06)</a>:</h4>
<p>The body of a bultin macro never actually runs - the actual definition is in the compiler code</p>



<a name="233424155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424155">(Apr 07 2021 at 03:07)</a>:</h4>
<p>I ask about <code>macro</code> because I saw that it's being used for the recently-stabilized <code>std::ptr::addr_of</code>, which must indicate some level of maturity of the implementation :)</p>



<a name="233424246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424246">(Apr 07 2021 at 03:09)</a>:</h4>
<p>/me coughs</p>



<a name="233424270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424270">(Apr 07 2021 at 03:09)</a>:</h4>
<p>most certainly not <a href="https://github.com/rust-lang/rust/pull/77862#issuecomment-740744018">https://github.com/rust-lang/rust/pull/77862#issuecomment-740744018</a></p>



<a name="233424347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424347">(Apr 07 2021 at 03:10)</a>:</h4>
<p>there are <em>so</em> many hacks there</p>



<a name="233424378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424378">(Apr 07 2021 at 03:10)</a>:</h4>
<p>I wouldn't have approved it if it weren't blocking addr_of</p>



<a name="233424764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/builtin%20macros/near/233424764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/builtin.20macros.html#233424764">(Apr 07 2021 at 03:16)</a>:</h4>
<p>honestly I kind of wish they'd just used macro_rules!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>